package com.atguigu.spzx.service.user.controller;

import com.atguigu.spzx.service.user.service.UserInfoService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.h5.UserInfoDto;
import com.atguigu.spzx.model.entity.h5.UserInfo;
import com.atguigu.spzx.model.vo.h5.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * title:
 * author: zgl
 * date: 2024/1/16
 * description：
 */
@RestController
@RequestMapping("/api/user/userInfo")
@Tag(name = "用户模块")
public class UserInfoController {
    @Resource
    private UserInfoService userInfoService;

    @PostMapping("/register")
    @Operation(summary = "注册接口")
    public Result register(@RequestBody UserInfoDto userInfoDto) {
        userInfoService.register(userInfoDto);
        return Result.ok();
    }

    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody UserInfo userInfo) {
        String token = userInfoService.login(userInfo);
        return Result.ok(token);
    }

    @Operation(summary = "获取当前登录用户信息接口")
    @GetMapping("/auth/getCurrentUserInfo")
    public Result getUserInfo(@RequestHeader String token) {
        UserInfoVo userInfoVo = userInfoService.getUserInfo(token);
        return Result.ok(userInfoVo);
    }

    @Operation(summary = "退出登录接口")
    @GetMapping("/logout")
    public Result logout(@RequestHeader String token) {
        userInfoService.logout(token);
        return Result.ok();
    }


}
